package com.smomo.blog.service.impl;

import com.smomo.blog.common.ResponseResult;
import com.smomo.blog.entity.AProduct;
import com.smomo.blog.mapper.AProductMapper;
import com.smomo.blog.service.IAProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-12-12
 */
@Service
public class AProductServiceImpl extends ServiceImpl<AProductMapper, AProduct> implements IAProductService {

    @Override
    public ResponseResult buy() {

        boolean update = this.update()
                .setSql("stock=stock-1")
                .eq("id", 1)
                .gt("stock", 0).update();
        if (update)
        {
            return ResponseResult.success("抢购成功");
        }

        return ResponseResult.success("失败");
    }
}
